/****************************************************************************
 *  QLyrics - A simple lyrics viewer.                                       *
 *  Copyright (C) 2008  hsys <hanshuiys@gmail.com>                          *
 *                                                                          *
 *  This program is free software; you can redistribute it and/or modify    *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation; either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  This program is distributed in the hope that it will be useful,         *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with this program; if not, write to the Free Software Foundation, *
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA       *
 ****************************************************************************/

#ifndef _LYRICSJOB_H_
#define _LYRICSJOB_H_

#include <vector>
#include <QObject>
#include "lyricsprovider.h"

/** A class to handle lyrics searching job. */
class LyricsJob : public QObject {
    Q_OBJECT
public:
    /** Create a job to search specific track.*/
    LyricsJob(const Track& track, QObject* parent = 0) : QObject(parent) 
    { m_track = track; m_prompt = false; };

    /** Add a lyrics provider to the job. */
    void addProvider(LyricsProvider::Builder* p) { m_list.push_back(p); };
    /** Return current searching status. */
    LyricsProvider::LyricsStatus getStatus() const { return m_status; };
    /** Return the file name of lyrics that has been downloaded. */
    const QString& getFilename() const { return m_filename; };
    /** Return currently used lyrics provider. */
    LyricsProvider* getCurrentProvider() { return m_p; };
    /** If set true, it will emit MultiChoice singal even if there is only one result. */
    void setIsPrompt(bool val) { m_prompt = val; };
    /** Start the job, and return the function immediately. */
    void start();

private:
    std::vector<LyricsProvider::Builder*> m_list;
    std::vector<LyricsProvider::Builder*>::const_iterator m_cur;
    LyricsProvider* m_p;
    Track m_track;
    LyricsProvider::LyricsStatus m_status;
    QString m_filename;

    bool m_prompt;

private slots:
    void slotJobSearched();
    void slotJobDone();

signals:
    void signalMultiChoice(LyricsJob*);
    void signalJobDone(LyricsJob*);
};

#endif
